<?php include_once 'layout/heard.php'?>
<body style="background:#f5f5f5; padding-bottom:50px;">

<div class="content head_bg">
	<div class="head">
        <div class="nav_ico">
        	<span class="ico01"></span>
            <span class="ico02"></span>
            <span class="ico03"></span>
        </div>
        <h1>配送中</h1>
        <a href="?md=riders&cl=riders&at=messageConten" class="news_ico"><span><?php echo $newCount; ?></span></a>
    </div>
</div>

<div class="nav_hs"></div>
<div class="nav_bg">
    <div class="nav_com">
        <dl>
            <dd><img src="webroot/riders/images/logo.png"></dd>
            <dt><?php echo $_SESSION['riders']['tel']?></dt>
        </dl>
        <ul>
            <li><a class="grxx" href="?md=riders&cl=riders&at=personageInfo">个人信息</a></li>
            <li><a class="lsdd" href="?md=riders&cl=riders&at=orderHistory">历史订单</a></li>
            <li><a class="wdqb" href="?md=riders&cl=riders&at=myWallet">我的钱包</a></li>
            <li><a class="cjwt" href="?md=riders&cl=riders&at=FQA">常见问题</a></li>
            <li><a class="xxzx" href="?md=riders&cl=riders&at=messageConten">消息中心</a></li>
        </ul>
    </div>
</div>

<div class="content order_list_bg">
	<div class="order_list">
    	<ul>
            <?php foreach($rsp_list as $v){
                if($v['shop_delivery_address']){
                    $address = $v['shop_delivery_address'];
                }else{
                    $address = $v['orders']['receiver_address'];
                }
                echo '<li id="express_'.$v['id'].'">
                        <h3>
                          <p>'.$v['shop_delivery_time'].'&nbsp;前送达</p>
                            <span>￥<b>'.($v['express_fee']+$v['tip']).'</b></span>                
                        </h3>
                        <h4>
                           <b>取货点：'.$v['orders']['shop_name'].'</b>
                       	    <span>'.$v['shop']['front_address'].'</span>
                        </h4>
                       <h5>收货点：'.$address.'</h5>
                        <label>配送距离：<span>'.round($v['orders']['distance']/1000,2).'</span> 公里</label>
                        <div class="box_bnt">
                            <a href="?md=riders&cl=riders&at=orderDetails_delivery&express_id='.$v['id'].'">查看详情</a>
                            <a class="bnt_hpsd" href="javascript:void(0)" code="'.$v['id'].'">货品送达</a>
                        </div>
                    </li>';
             }?>
        </ul>
    </div>
</div>

<?php if($rsp_list){
    $display = 'style="display: none"';
}else{
    $display = '';
}
?>
<div class="content no_order" <?php echo $display?>>
	<dl>
        <dd><img src="webroot/riders/images/no_order.png"></dd>
        <dt>还没有配送中的订单，快去抢单吧！</dt>
    </dl>
</div>

<div class="menu_bg">
    <div class="content">
        <a class="a_xrw" href="?md=riders&cl=riders&at=OrdersList">
            <span></span>
            <p>新任务</p>
        </a>
        <a class="a_dqh" href="?md=riders&cl=riders&at=assignPick">
            <span></span>
            <p>待取货</p>
        </a>
        <a class="a_psz hov new" href="?md=riders&cl=riders&at=dispatching">
            <span></span>
            <p>配送中</p>
        </a>
        <a class="a_ywc " href="?md=riders&cl=riders&at=finishOrderList">
            <span></span>
            <p>已完成</p>
        </a>
    </div>
</div>

<a class="bnt_refresh" href="javascript:location.reload();">刷新</a>

<div class="group_tc_bg" id="hpsd_pop">
    <div class="group_tc">
        <h3>温馨提示！</h3>
        <p>请确认货品已送达，如发现虚假按货品送达将面临50元一次惩罚！</p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">还未送达</a>
            <a href="javascript:void(0)" class="btn2">确认送达</a>
        </div>
    </div>
</div>

<div class="group_tc_bg" id="hpsd_qr_pop" style="z-index: auto;">
    <div class="group_tc">
        <h3>订单配送完成确认</h3>
        <div class="com">
            <div class="box">
                <label>订单配送情况：</label>
                <select name="finishSelect" id="finishSelect">
                    <option value="">请选择</option>
                    <option value="1">本人签收</option>
                    <option value="2">家人/门卫代签</option>
                    <option value="6">异常订单</option>
                </select>
            </div>
          	<div class="box">
                <label>骑手备注：</label>
                <textarea class="text" name="remark" id="remark" @blur="scrollto0"></textarea>
            </div>
        </div>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">取消</a>
            <a href="javascript:void(0)" class="btn2">确认</a>
        </div>
    </div>
</div>


<div class="group_tc_bg" id="zhty_pop">
    <div class="group_tc">
        <h3>很遗憾！</h3>
        <p>您的骑手资格已被门店停用，请联系门店人员，开启后才可恢复接单。</p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">暂不联系</a>
            <a href="javascript:void(0)" class="btn2">立即联系</a>
        </div>
    </div>
</div>

<div class="group_tc_bg" id="ridersT">
    <div class="group_tc">
        <h3>很遗憾！</h3>
        <p id="con"></p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">取消</a>
            <a href="?md=riders&cl=riders&at=riders_approve" class="btn2">再次认证</a>
        </div>
    </div>
</div>

<div class="group_tc_bg" id="ridersD">
    <div class="group_tc">
        <h3>很遗憾！</h3>
        <p>您当前尚未提交审核资料，请提交认证资料。</p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">取消</a>
            <a href="?md=riders&cl=riders&at=riders_approve" class="btn2">去认证</a>
        </div>
    </div>
</div>


<div class="group_tc_bg" id="ridersB">
    <div class="group_tc">
        <h3>很遗憾！</h3>
        <p>您提交审核资料不符合要求。</p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">取消</a>
            <a href="javascript:void(0)" class="btn2">确定</a>
        </div>
    </div>
</div>


<div class="group_tc_bg" id="ridersC">
    <div class="group_tc">
        <!--        <h3>很遗憾！</h3>-->
        <p>资料已提交 请耐心等待审核结果。</p>
        <div class="bnt">
            <a href="javascript:void(0)" class="btn1">取消</a>
            <a href="javascript:void(0)" class="btn2">确定</a>
        </div>
    </div>
</div>
<script>
    $("#hpsd_qr_pop .btn2").click(function(){
        var express_id = $(this).attr('code');
        var type = $(this).next().text();
        var finishSelect = $("#finishSelect").val();
        var remark = $("#remark").val();

        if(!finishSelect || !express_id){
            popup("请正确填写");
            return false;
        }
        if(!finishSelect){
            popup("订单签收状态不可为空");
            return false;
        }
        $.ajax({
            url:"?md=riders&cl=riders&at=finish",
            type:"post",
            dataType:"json",
            data:{'express_id':express_id,'finishSelect':finishSelect,'remark':remark},
            success:function (d) {
                $("#hpsd_qr_pop .btn1").click();
                if(d.status == 1){
                    popup("配送完成");
                    $("#express_"+express_id).remove();
                    // location.href = "?md=riders&cl=riders&at=dispatching";
                }else{
                    popup(d.msg);
                    // $("#qrqh_pop").fadeOut();
                }
            }
        })
    });
    $("#hpsd_qr_pop .btn1").click(function(){
        $("#hpsd_qr_pop").fadeOut();
    });

    $("#finishSelect").blur(function () {
        setTimeout(() => {
            const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
            window.scrollTo(0, Math.max(scrollHeight - 1, 0));
        }, 100);
    });
    $("#remark").blur(function () {
        setTimeout(() => {
            const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
            window.scrollTo(0, Math.max(scrollHeight - 1, 0));
        }, 100);
    });
    $(function () {
        $.ajax({
            url:"?md=riders&cl=riders&at=ridersT",
            type:"post",
            dataType:"json",
            data:{'tel':13888888888},
            success:function (d) {
                console.log(d)
                if( d.status == 1 && d.initiate == 2){  // 审核通过 但被停用
                    $("#zhty_pop").fadeIn();
                }
                if (d.status == 4) {                    // 审核通过 禁止接单
                    $("#zhty_pop").fadeIn();
                }

                if ( d.status == 10) {  // 没有提交审核资料 / 刚注册 = 10
                    $("#ridersD").fadeIn();
                }
                if(d.status == 0){      // 0 = 已经提交未审核
                    $("#ridersC").fadeIn();
                }

                if (d.status == 3){                     // 审核未通过
                    $("#con").html("骑手认证资料审核未通过，请查看未通过理由后，可重新填写再次提交认证。<br>未通过理由："+d.msg);
                    $("#ridersT").fadeIn();
                    $("#riderReg").show();
                }

                if (d.status == 2){                     // 审核未通过 不得申请
                    $("#ridersB").fadeIn();
                }

            }
        })
    })



    // ------------------------------------------------ 是否有被取消订单 --------------------------------------- //
    $.ajax({
        url:"?md=riders&cl=riders&at=getCanCelOrders",
        type:"post",
        dataType:"json",
        success:function (d) {
            if(d.status == 1){
                popup(d.msg);
                // $(d.result).each(function (k,v) {
                // 	$("#Cancel").find('p').html("取货点："+v.address+'<br/>收货点：'+v.receiver_address);
                // 	$("#Cancel").fadeIn();
                // });
            }
        }
    })
</script>
<?php include_once 'layout/rfooter.php'?>